package cn.tedu.charging.device.service.impl;

import cn.tedu.charging.common.pojo.param.GunStatusUpdateParam;
import cn.tedu.charging.device.dao.repository.StationCacheRepository;
import cn.tedu.charging.device.pojo.StationPO;
import cn.tedu.charging.device.service.DeviceService;
import cn.tedu.charging.common.pojo.vo.StationInfoVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@Service
public class DeviceServiceImpl implements DeviceService {

    @Autowired
    @Qualifier("GEOANDShareHash")
    private StationCacheRepository stationCacheRepository;

    @Override
    public StationInfoVO getStationInfo(Integer gunId) {
        StationInfoVO stationInfoVO = new StationInfoVO();
        stationInfoVO.setId(1);
        return stationInfoVO;
    }

    @Override
    public Boolean updateGunStatus(GunStatusUpdateParam gunStatusUpdateParam) {
        return true;
    }

    @Override
    public List<StationInfoVO> getNearStation(Double longitude, Double latitude, Double distance) {

        List<StationPO> searchResult =
                stationCacheRepository.search(longitude, latitude, distance);

        List<StationInfoVO> result = new ArrayList<>();

        if (!CollectionUtils.isEmpty(searchResult)) {

            for (StationPO stationPO : searchResult) {
                StationInfoVO stationInfoVO = new StationInfoVO();
                BeanUtils.copyProperties(stationPO, stationInfoVO);
                result.add(stationInfoVO);
            }
        }
        return result;
    }
}